package org.scau.studentevaluation.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.extern.slf4j.Slf4j;
import org.scau.studentevaluation.entity.bo.ConstructorBO;
import org.scau.studentevaluation.entity.dos.ActDO;
import org.scau.studentevaluation.entity.dos.UserDO;
import org.scau.studentevaluation.entity.bo.UserBO;
import org.scau.studentevaluation.entity.query.UserQuery;
import org.scau.studentevaluation.entity.vo.UserVO;
import org.scau.studentevaluation.util.BeanConvertUtils;
import org.scau.studentevaluation.service.IUserService;
import org.scau.studentevaluation.service.ImportMapperService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

@Slf4j
@Service
public class UserServiceImpl implements IUserService{
    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private ImportMapperService importMapperService;


    @Override
    public UserDO getUserData(long userId) {
        LambdaQueryWrapper<UserDO> query = Wrappers.<UserDO>lambdaQuery()
                .eq(UserDO::getId, userId)
                .last(" limit 1");
        UserDO DO = importMapperService.userMapper.selectOne(query);
        if (DO == null) {
            // 数据库里面没有的话，统一返回学生会
            return null;
        }
        return DO;
    }

    @Override
    public int insertUserData(UserQuery userQuery){
        LambdaQueryWrapper<UserDO> query=Wrappers.<UserDO>lambdaQuery()
                .eq(UserDO::getId,userQuery.getUserId())
                .last(" limit 1");
                //.eq(UserDO::getUserData,userQuery.getUserData())

        int count =importMapperService.userMapper.selectCount(query);
        userQuery.getUserId();
        if(count==0){
            UserDO userDO = new UserDO();
            BeanUtils.copyProperties(userQuery, userDO);
            userDO.setId(userQuery.getUserId());
            return importMapperService.userMapper.insert(userDO);
        }
        return 0;
    }


}
